package com.baizhi.utils.hutool;

import cn.hutool.core.io.IoUtil;
import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class IoUtilTest {

    @Test
    public void test1() throws Exception {
        // 原始文件拷贝
        InputStream input = new FileInputStream("src/main/resources/files/1.txt");
        OutputStream output = new FileOutputStream("src/main/resources/files/2.txt");
        byte[] bytes = new byte[1024];
        int len;
        while ((len = input.read(bytes)) != -1) {
            output.write(bytes, 0, len);
        }
        input.close();
        output.close();
    }

    @Test
    public void test2() throws Exception {
        InputStream input = new FileInputStream("src/main/resources/files/1.txt");
        OutputStream output = new FileOutputStream("src/main/resources/files/3.txt");
        // IoUtil.copy(input, output);
        IoUtil.copy(input, output, 2048);   // 指定缓冲区大小
    }
}
